package hashTable;

import java.util.ArrayList;
import java.util.List;

public class N438_FindAllAnagrams {
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> list = new ArrayList<Integer>();
        int[] arr = new int[26];
        for (int i = 0; i < p.length(); i++)
            arr[p.charAt(i) - 'a']++;
        for (int left = 0, right = p.length() - 1; right < s.length(); left++, right++) {
            int[] arrp = arr.clone();
            boolean flag = true;
            for (int i = left; i <= right; i++)
                arrp[s.charAt(i) - 'a']--;
            for (int i : arrp) {
                if (i > 0) {
                    flag = false;
                    continue;
                }
            }
            if (flag) {
                list.add(left);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        N438_FindAllAnagrams solution = new N438_FindAllAnagrams();
        List<Integer> list = solution.findAnagrams("abab", "a");
        for (Integer i : list) {
            System.out.print(i + "\t");
        }
    }
}
